#include <cstdio>

const int N = 1000005;
int n;
int e_cnt, heads[N + 10000], match[N + 10000], vis[N + 10000];

struct Edge {
  int v, nxt;
} e[N << 2];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

bool dfs(int x, int tim) {
  if (vis[x] == tim) return false;
  vis[x] = tim;
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if (!match[v = e[i].v] || dfs(match[v], tim)) {
      match[v] = x;
      return true;
    }
  }
  return false;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("P1640 [SCOI2010]连续攻击游戏.in", "r", stdin);
  freopen("P1640 [SCOI2010]连续攻击游戏.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1, a, b; i <= n; ++i) {
    scanf("%d%d", &a, &b);
    add(a, i + 10000), add(i + 10000, a);
    add(b, i + 10000), add(i + 10000, b);
  }
  int ans = 0;
  for (int i = 1; i <= 10000; ++i) {
    if (dfs(i, i))
      ++ans;
    else
      break;
  }
  printf("%d", ans);
  return 0;
}